package com.tzstcl.sys.webSocket.service.impl;

import com.tzstcl.sys.webSocket.service.WebSocketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

/**
 * WebSocket接口服务
 */
@Service
public class WebSocketServiceImpl implements WebSocketService {

    @Autowired
    SimpMessagingTemplate simpMessagingTemplate;

    /**
     * 发送全局消息
     */
    @Override
    public void sendGlobalMessage(String message) {
        simpMessagingTemplate.convertAndSend("/channel/global", message);
    }

    /**
     * 发送分组消息
     */
    @Override
    public void sendGroupMessage(String groupId, String message) {
        simpMessagingTemplate.convertAndSend("/channel/group/" + groupId, message);
    }

    /**
     * 发送点对点消息
     */
    @Override
    public void sendPointMessage(String userId, String message) {
        simpMessagingTemplate.convertAndSendToUser(userId, "/channel/user", message);
    }

}
